#include "AlapForm.h"

using namespace Osp::Base;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;
using namespace Osp::Locations;
//using namespace Osp::Locations::Services;

AlapForm::AlapForm(void)
{
}

AlapForm::~AlapForm(void)
{
}

bool
AlapForm::Initialize()
{
	// Construct an XML form
	Construct(L"IDF_ALAPFORM");

	return true;
}

result
AlapForm::OnInitializing(void)
{
	result r = E_SUCCESS;

	// TODO: Add your initialization code here

	// Get a button via resource ID
	__pButtonOk = static_cast<Button *>(GetControl(L"IDC_BUTTON_OK"));
	if (__pButtonOk != null)
	{
		__pButtonOk->SetActionId(ID_BUTTON_OK);
		__pButtonOk->AddActionEventListener(*this);
	}

	__pLongitudeLabel = static_cast<Label *>(GetControl(L"LON"));
	__pAltitudeLabel = static_cast<Label *>(GetControl(L"ALT"));

	locProvider = new LocationProvider();
	locProvider->Construct(LOC_METHOD_HYBRID);
	locProvider->RequestLocationUpdates(*this, 5, false);
	return r;
}

result
AlapForm::OnTerminating(void)
{
	result r = E_SUCCESS;

	// TODO: Add your termination code here

	return r;
}

void
AlapForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
	switch(actionId)
	{
	case ID_BUTTON_OK:
		{


		}
		break;
	default:
		break;
	}
}

void
AlapForm::OnLocationUpdated(Location& location)
{
    if(location.GetQualifiedCoordinates()!=null)
    {
    	AppLog("beleptem");
        const QualifiedCoordinates *q = location.GetQualifiedCoordinates();
        double longitude = q->GetLongitude();
        double latitude = q->GetLatitude();
        String longitude_string, latitude_string;
        q->Convert(longitude,DD_MM_SS,longitude_string);
        q->Convert(latitude,DD_MM_SS,latitude_string);

        __pLongitudeLabel->SetText(longitude_string);
        __pAltitudeLabel->SetText(latitude_string);

        AppLog("%d %d", longitude, latitude);
        RequestRedraw(true);
    }
}

void
AlapForm::OnProviderStateChanged(LocProviderState newState){}

